import Vue from 'vue'
import Vuex from 'vuex'
import axios from 'axios'
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    list: []
  },
  mutations: {
    SET_LIST(state, payload) {
    // 设置数据
      state.list = payload
    }
  },
  actions: {
    async fetchList({ commit }, searchValue) {
      // 请求数据
      const resp = await axios.get('/api/lists', { params: { searchValue } });
      // 解构数据
      const { data } = resp.data;
      // 提交mutations
      commit('SET_LIST', data)
    }
  },
  modules: {
  }
})
